package com.dyb.idempotent.controller;

import com.dyb.idempotent.annotation.ExtApiIdempotent;
import com.dyb.idempotent.annotation.ExtApiToken;
import com.dyb.idempotent.service.RedisTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @ProjectName: idempotent
 * @Package: com.dyb.idempotent.controller
 * @ClassName: TestController2
 * @Author: Deng YuBin
 * @Description:
 * @Date: 2021/1/14 20:41
 * @Version: 1.0
 */
@Controller
public class TestController2 {

    @Autowired
    RedisTokenService tokenService;

    @RequestMapping(value = "/indexPage")
    @ExtApiToken //加该注解代表会被先执行AOP逻辑
    public String indexPage(HttpServletRequest request) {
        System.out.println("================================");
        //加上注解ExtApiToken，使用AOP方式统一设置token
        //request.setAttribute("token",tokenService.getToken());
        return "indexPage";
    }

    @RequestMapping(value = "/addUserPage")
    @ResponseBody
    @ExtApiIdempotent(type = "form")  //表单form要校验token
    public String addUserPage(HttpServletRequest request) {
        return "添加成功！";
    }
}